Merge "RCFilters: Live Update: download less data"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 6 Sep 2017 21:10:08 +0000 (21:10 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 6 Sep 2017 21:10:08 +0000 (21:10 +0000)
includes/specialpage/ChangesListSpecialPage.php
resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js

index 5f54404..04d03f5 100644 (file)
@@ -519,16 +519,25 @@ abstract class ChangesListSpecialPage extends SpecialPage {
        public function execute( $subpage ) {
                $this->rcSubpage = $subpage;
 
-               $this->setHeaders();
-               $this->outputHeader();
-               $this->addModules();
-
                $rows = $this->getRows();
                $opts = $this->getOptions();
                if ( $rows === false ) {
                        $rows = new FakeResultWrapper( [] );
                }
 
+               // Used by Structured UI app to get results without MW chrome
+               if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
+                       $this->getOutput()->setArticleBodyOnly( true );
+               }
+
+               // Used by "live update" and "view newest" to check
+               // if there's new changes with minimal data transfer
+               if ( $this->getRequest()->getBool( 'peek' ) ) {
+                       $code = $rows->numRows() > 0 ? 200 : 304;
+                       $this->getOutput()->setStatusCode( $code );
+                       return;
+               }
+
                $batch = new LinkBatch;
                foreach ( $rows as $row ) {
                        $batch->add( NS_USER, $row->rc_user_text );
@@ -542,6 +551,10 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                        }
                }
                $batch->execute();
+
+               $this->setHeaders();
+               $this->outputHeader();
+               $this->addModules();
                $this->webOutput( $rows, $opts );
 
                $rows->free();
index 81bfb47..8d0aa05 100644 (file)
                        'liveUpdate',
                        {
                                limit: 1,
+                               peek: 1, // bypasses all UI
                                from: this.changesListModel.getNextFrom()
                        }
                );
 
                counterId = counterId || 'updateChangesList';
                params = params || {};
+               params.action = 'render'; // bypasses MW chrome
 
                uri.extend( params );
 
 
                return $.ajax( uri.toString(), { contentType: 'html' } )
                        .then(
-                               function ( html ) {
+                               function ( html, reason ) {
                                        var $parsed,
                                                pieces;
 
                                                return $.Deferred().reject();
                                        }
 
-                                       $parsed = $( $.parseHTML( html ) );
+                                       if ( params.peek && reason === 'notmodified' ) {
+                                               return {
+                                                       changes: 'NO_RESULTS'
+                                               };
+                                       }
+
+                                       // Because of action=render, the response is a list of nodes.
+                                       // It has to be put under a root node so it can be queried.
+                                       $parsed = $( '<div>' ).append( $( $.parseHTML( html ) ) );
 
                                        pieces = {
                                                // Changes list